package com.example.demo.controller;

import com.example.demo.core.StandardResult;
import com.example.demo.domain.TeacherEntity;
import com.example.demo.service.impls.TeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Random;
import java.util.UUID;

@RestController
@RequestMapping("/teacher")
@Api(value = "TeacherController",description = "教师模块接口")
public class TeacherController extends BaseController {
    @Autowired
    private TeacherService teacherService;

    @ApiOperation(value = "获取所有教师信息value",notes ="获取所有教师信息notes" )
    @RequestMapping(value = "/query",method = RequestMethod.GET)
    public StandardResult query() {
        List<TeacherEntity> teacherEntities = teacherService.queryList();

        return success(teacherEntities);
    }

    @ApiOperation(value = "根据ID获取教师信息v",notes ="根据ID获取教师信息n" )
    @ApiImplicitParam(name = "id",value = "主键ID",required = true,dataType = "int",paramType = "path")
    @RequestMapping(value = "/get/{id}",method = RequestMethod.GET)
    public StandardResult get(@PathVariable("id") int id) {

        TeacherEntity entity = teacherService.getById(id);

        return success(entity);
    }

    @RequestMapping(value = "/save/{id}",method = RequestMethod.GET)
    public boolean saveTeacher(@PathVariable int id) {
        Random random = new Random();

        TeacherEntity teacherEntity = new TeacherEntity();
        teacherEntity.setId(id);
        teacherEntity.setName("姓名" + random.nextInt());
        teacherEntity.setPassword(UUID.randomUUID().toString());
        boolean result = teacherService.insert(teacherEntity);

        return result;
    }

    @RequestMapping(value = "/save/{id}/{name}/{password}",method = RequestMethod.GET)
    public boolean saveTeacher(@PathVariable int id, @PathVariable("name") String name, @PathVariable("password") String password) {

        TeacherEntity teacherEntity = new TeacherEntity();
        teacherEntity.setId(id);
        teacherEntity.setName(name);
        teacherEntity.setPassword(password);

        boolean result = teacherService.insert(teacherEntity);

        return result;
    }

    @ApiOperation(value = "更新教师信息v",notes = "更新教师信息n")
    @ApiImplicitParams({
            @ApiImplicitParam (name = "id",value = "主键ID",required = true,dataType = "int",paramType = "path"),
            @ApiImplicitParam (name = "name",value = "教师姓名",required = true,dataType = "int",paramType = "path")
    })
    @RequestMapping(value = "/update/{id}/{name}",method = RequestMethod.GET)
    public boolean updateTeacher(@PathVariable int id, @PathVariable String name) {

        TeacherEntity teacherEntity = new TeacherEntity();
        teacherEntity.setId(id);
        teacherEntity.setName(name);
        boolean result = teacherService.update(teacherEntity);

        return result;
    }

    @RequestMapping(value = "/delete/{id}",method = RequestMethod.GET)
    public boolean deleteTeacher(@PathVariable int id) {

        TeacherEntity teacherEntity = new TeacherEntity();
        teacherEntity.setId(id);
        boolean result = teacherService.delete(teacherEntity);

        return result;
    }

    @RequestMapping(value = "/delete1/{id}",method = RequestMethod.GET)
    public boolean deleteTeacher1(@PathVariable int id) {

        boolean result = teacherService.delete(id);

        return result;
    }
}
